import request from './index'

interface LoginParams {
  phone: string
  password?: string
  code?: string
}

interface RegisterParams {
  phone: string
  password: string
  code: string
}

interface ResetPasswordParams {
  phone: string
  code: string
  newPassword: string
}

// 密码登录
export const loginByPassword = (data: LoginParams) => {
  return request({
    url: '/users/loginPw',
    method: 'post',
    data
  })
}

// 验证码登录
export const loginByCode = (data: LoginParams) => {
  return request({
    url: '/users/loginCode',
    method: 'post',
    data
  })
}

// 注册
export const register = (data: RegisterParams) => {
  return request({
    url: '/users/register',
    method: 'post',
    data
  })
}

// 重置密码
export const resetPassword = (data: ResetPasswordParams) => {
  return request({
    url: '/users/resetPassword',
    method: 'post',
    data
  })
}

// 发送验证码
export const sendCode = (phone: string) => {
  return request({
    url: '/sms/sendCode',
    method: 'post',
    data: { phone }
  })
}

// 获取用户信息
export const getUserInfo = () => {
  return request({
    url: '/users/info',
    method: 'get'
  })
}
